<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Nginx安装配置 | 海内存知已，天涯若比邻</title><meta name="keywords" content="nginx"><meta name="author" content="mowei"><meta name="copyright" content="mowei"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="0、Nginx 安装 关于版本： Nginx开源版    http:&#x2F;&#x2F;nginx.org&#x2F; Nginx plus 商业版    https:&#x2F;&#x2F;www.nginx.com openresty    http:&#x2F;&#x2F;openresty.org&#x2F;cn&#x2F; Tengine    http:&#x2F;&#x2F;tengine.taobao.org&#x2F;  1、下载上传文件 2、编译安装 123.&#x2F;configure --pre">
<meta property="og:type" content="article">
<meta property="og:title" content="Nginx安装配置">
<meta property="og:url" content="https://gitee.com/momomomowei/blog/nginx/Nginx%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/index.html">
<meta property="og:site_name" content="海内存知已，天涯若比邻">
<meta property="og:description" content="0、Nginx 安装 关于版本： Nginx开源版    http:&#x2F;&#x2F;nginx.org&#x2F; Nginx plus 商业版    https:&#x2F;&#x2F;www.nginx.com openresty    http:&#x2F;&#x2F;openresty.org&#x2F;cn&#x2F; Tengine    http:&#x2F;&#x2F;tengine.taobao.org&#x2F;  1、下载上传文件 2、编译安装 123.&#x2F;configure --pre">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/momomomowei/images/nginx.png">
<meta property="article:published_time" content="2023-03-18T06:06:43.000Z">
<meta property="article:modified_time" content="2024-04-21T07:24:14.404Z">
<meta property="article:author" content="mowei">
<meta property="article:tag" content="nginx">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/momomomowei/images/nginx.png"><link rel="shortcut icon" href="/media/favicon.png"><link rel="canonical" href="https://gitee.com/momomomowei/blog/nginx/Nginx%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: true,
  islazyload: true,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Nginx安装配置',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2024-04-21 15:24:14'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const fontSizeVal = saveToLocal.get('global-font-size')
    if (fontSizeVal !== undefined) {
      document.documentElement.style.setProperty('--global-font-size', fontSizeVal + 'px')
    }
    
    const detectApple = () => {
      if (GLOBAL_CONFIG_SITE.isHome && /iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    document.addEventListener('pjax:complete', detectApple)})(window)</script><meta name="generator" content="Hexo 5.4.2"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "" data-lazy-src="/media/avatar.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">41</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">29</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">7</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 目录</span><i class="fas fa-chevron-down expand hide"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/images/nginx.png')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">海内存知已，天涯若比邻</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 目录</span><i class="fas fa-chevron-down expand hide"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Nginx安装配置</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-03-18T06:06:43.000Z" title="发表于 2023-03-18 14:06:43">2023-03-18</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2024-04-21T07:24:14.404Z" title="更新于 2024-04-21 15:24:14">2024-04-21</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/nginx/">nginx</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">3.1k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>12分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Nginx安装配置"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="0、Nginx-安装"><a href="#0、Nginx-安装" class="headerlink" title="0、Nginx 安装"></a>0、Nginx 安装</h2><blockquote>
<p>关于版本：</p>
<p><strong>Nginx开源版</strong><br>    <a target="_blank" rel="noopener" href="http://nginx.org/">http://nginx.org/</a></p>
<p><strong>Nginx plus 商业版</strong><br>    <a target="_blank" rel="noopener" href="https://www.nginx.com">https://www.nginx.com</a></p>
<p><strong>openresty</strong><br>    <a target="_blank" rel="noopener" href="http://openresty.org/cn/">http://openresty.org/cn/</a></p>
<p><strong>Tengine</strong><br>    <a target="_blank" rel="noopener" href="http://tengine.taobao.org/">http://tengine.taobao.org/</a></p>
</blockquote>
<p>1、下载上传文件</p>
<p>2、编译安装</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">./configure --prefix=/usr/local/nginx</span><br><span class="line">make</span><br><span class="line">make install</span><br></pre></td></tr></table></figure>
<blockquote>
<p>如果出现警告，安装依赖</p>
<p>yum install -y gcc</p>
<p>yum install -y pcre pcre-devel</p>
<p>yum install -y zlib zlib-devel</p>
</blockquote>
<p>3、启动Nginx</p>
<p>进入安装好的目录<code>/usr/local/nginx/sbin</code></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">./nginx 			启动</span><br><span class="line">./nginx -s stop 	快速停止</span><br><span class="line">./nginx -s quit 	优雅关闭，在退出前完成已经接受的连接请求</span><br><span class="line">./nginx -s reload 	重新加载配置</span><br></pre></td></tr></table></figure>
<blockquote>
<h1 id="关闭防火墙"><a href="#关闭防火墙" class="headerlink" title="关闭防火墙"></a>关闭防火墙</h1><p>systemctl stop firewalld.service</p>
<h1 id="禁止防火墙开机启动"><a href="#禁止防火墙开机启动" class="headerlink" title="禁止防火墙开机启动"></a>禁止防火墙开机启动</h1><p>systemctl disable firewalld.service</p>
<h1 id="放行端口"><a href="#放行端口" class="headerlink" title="放行端口"></a>放行端口</h1><p>firewall-cmd —zone=public —add-port=80/tcp —permanent</p>
<h1 id="重启防火墙"><a href="#重启防火墙" class="headerlink" title="重启防火墙"></a>重启防火墙</h1><p>firewall-cmd —reload</p>
</blockquote>
<p>4、安装成系统服务</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">创建服务脚本</span></span><br><span class="line">vi /usr/lib/systemd/system/nginx.service</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">服务脚本内容（注意安装目录是否正确）</span></span><br><span class="line">[Unit]</span><br><span class="line">Description=nginx - web server</span><br><span class="line">After=network.target remote-fs.target nss-lookup.target</span><br><span class="line">[Service]</span><br><span class="line">Type=forking</span><br><span class="line">PIDFile=/usr/local/nginx/logs/nginx.pid</span><br><span class="line">ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf</span><br><span class="line">ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf</span><br><span class="line">ExecReload=/usr/local/nginx/sbin/nginx -s reload</span><br><span class="line">ExecStop=/usr/local/nginx/sbin/nginx -s stop</span><br><span class="line">ExecQuit=/usr/local/nginx/sbin/nginx -s quit</span><br><span class="line">PrivateTmp=true</span><br><span class="line"></span><br><span class="line">[Install]</span><br><span class="line">WantedBy=multi-user.target</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">重新加载系统服务</span></span><br><span class="line">systemctl daemon-reload</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">启动服务</span></span><br><span class="line">systemctl start nginx.service</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">开机启动</span></span><br><span class="line">systemctl enable nginx.service</span><br></pre></td></tr></table></figure>
<h2 id="1、目录结构"><a href="#1、目录结构" class="headerlink" title="1、目录结构"></a>1、目录结构</h2><blockquote>
<p>conf        用来存放配置文件相关<br>html        用来存放静态文件的默认目录 html、css等<br>sbin        nginx的主程序</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">client_body_temp conf fastcgi_temp html logs proxy_temp sbin scgi_temp uwsgi_temp</span><br></pre></td></tr></table></figure>
<p>其中这几个文件夹在刚安装后是没有的，主要用来存放运行过程中的<code>临时文件</code></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">client_body_temp fastcgi_temp proxy_temp scgi_temp</span><br></pre></td></tr></table></figure>
<h2 id="2、最小化配置"><a href="#2、最小化配置" class="headerlink" title="2、最小化配置"></a>2、最小化配置</h2><blockquote>
<p>配置完成需要重新加载配置文件    <code>systemctl reload nginx</code></p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">开启的工作进程数量，一般跟cpu内核一样即可</span></span><br><span class="line">worker_processes  1;</span><br><span class="line"></span><br><span class="line">events &#123;</span><br><span class="line"><span class="meta prompt_">	#</span><span class="language-bash">最大连接数</span></span><br><span class="line">    worker_connections  1024;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">http &#123;</span><br><span class="line"><span class="meta prompt_">	#</span><span class="language-bash">include 表示引入其他配置文件</span></span><br><span class="line"><span class="meta prompt_">	#</span><span class="language-bash">mime.types简单理解成数据类型的定义</span></span><br><span class="line">    include       mime.types;</span><br><span class="line">    #默认发送的数据类型</span><br><span class="line">    default_type  application/octet-stream;</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">	#</span><span class="language-bash">简单理解，不通系统拷贝到内存，直接发送数据</span></span><br><span class="line">    sendfile        on;</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">	#</span><span class="language-bash">保持连接的时间</span></span><br><span class="line">    keepalive_timeout  65;</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">	#</span><span class="language-bash">虚拟主机（vhost）,可以有多个</span></span><br><span class="line">    server &#123;</span><br><span class="line">    	#监听的端口号</span><br><span class="line">        listen       80;</span><br><span class="line">        </span><br><span class="line">        #访问的主机名或者域名，可配置多个</span><br><span class="line">        #在前面配置通配符号，如 *.momo.com</span><br><span class="line">        #在后面配置通配符号，如 www.momo.*</span><br><span class="line">        server_name  localhost www.momoda.com;</span><br><span class="line">        </span><br><span class="line">        #匹配路径</span><br><span class="line">        #如https://www.baidu.com/momo.html，location则是/momo.html</span><br><span class="line">        location / &#123;</span><br><span class="line">        	#文件根目录，html是位于nginx安装位置下的html</span><br><span class="line">        	#注意root代表的是一个属性名（key），指的是站点的位置，如root /usr/local，root /www/video</span><br><span class="line">            #root   html;</span><br><span class="line">            root	/www/momo</span><br><span class="line">            #默认打开的首页，最左边的index是一个属性名（key）</span><br><span class="line">            index  index.html index.htm;</span><br><span class="line">        &#125;</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">		#</span><span class="language-bash">服务器发生错误时访问的路径，500 502 503 504表示发生的错误，/50x.html则是错误转发到的地址</span></span><br><span class="line">        error_page   500 502 503 504  /50x.html;</span><br><span class="line">        #定义上面的错误转发地址</span><br><span class="line">        location = /50x.html &#123;</span><br><span class="line">            root   html;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h2 id="3、虚拟主机"><a href="#3、虚拟主机" class="headerlink" title="3、虚拟主机"></a>3、虚拟主机</h2><blockquote>
<p><strong>servername匹配规则</strong></p>
<ul>
<li>匹配多个域名：server_name vod.mmban.com www1.mmban.com;</li>
<li>通配符匹配：server_name *.mmban.com</li>
<li>通配符结束匹配：server_name vod.*;</li>
<li>正则匹配：server_name ~^[0-9]+.mmban.com$;</li>
</ul>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">http &#123;</span><br><span class="line">    server &#123;</span><br><span class="line">        listen       80;</span><br><span class="line">        server_name  localhost www.momoda.com;</span><br><span class="line">        #server_name vod.mmban.com www1.mmban.com;</span><br><span class="line">        #server_name *.mmban.com</span><br><span class="line">        #server_name vod.*;</span><br><span class="line">        #server_name ~^[0-9]+\.mmban\.com$;</span><br><span class="line"></span><br><span class="line">        location / &#123;</span><br><span class="line">            root   html;</span><br><span class="line">            index  index.html index.htm;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        error_page   500 502 503 504  /50x.html;</span><br><span class="line">        location = /50x.html &#123;</span><br><span class="line">            root   html;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="4、反向代理"><a href="#4、反向代理" class="headerlink" title="4、反向代理"></a>4、反向代理</h2><blockquote>
<p>注意</p>
<ul>
<li><code>proxy_pass和root只能存在一个</code></li>
<li>proxy_pass也支持负载均衡</li>
<li>proxy_pass可以写域名和主机地址</li>
<li>proxy_pass<code>不能用于https</code></li>
<li>proxy_pass后面的http如果没有写www，如<a target="_blank" rel="noopener" href="http://baidu.com/，则页面会`重定向`到（其实nginx是生效的！）">http://baidu.com/，则页面会`重定向`到（其实nginx是生效的！）</a></li>
</ul>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line">upstream httpd &#123;</span><br><span class="line">    server 127.0.0.1:8050 weight=10 down;</span><br><span class="line">    server 127.0.0.1:8060 weight=1;</span><br><span class="line">    server 127.0.0.1:8060 weight=1 backup;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">http &#123;</span><br><span class="line">    server &#123;</span><br><span class="line">        listen       80;</span><br><span class="line"></span><br><span class="line">        location / &#123;</span><br><span class="line">        	#反向代理，不会重定向</span><br><span class="line">        	proxy_pass http://www.baidu.com/;</span><br><span class="line">        	#可以写主机地址</span><br><span class="line">        	#proxy_pass http:192.168.44.101;</span><br><span class="line">        	</span><br><span class="line">        	#反向代理，页面会重定向</span><br><span class="line">        	#proxy_pass http://baidu.com/;</span><br><span class="line">        	</span><br><span class="line">        	#只能同时存在一个</span><br><span class="line">            #root   html;</span><br><span class="line">            #index  index.html index.htm;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        error_page   500 502 503 504  /50x.html;</span><br><span class="line">        location = /50x.html &#123;</span><br><span class="line">            root   html;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    #负载均衡写法</span><br><span class="line">    server &#123;</span><br><span class="line">        listen       8888;</span><br><span class="line">        location / &#123;</span><br><span class="line">        	proxy_pass http://httpds;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="5、负载均衡"><a href="#5、负载均衡" class="headerlink" title="5、负载均衡"></a>5、负载均衡</h2><h3 id="5-1-配置负载均衡"><a href="#5-1-配置负载均衡" class="headerlink" title="5.1 配置负载均衡"></a>5.1 配置负载均衡</h3><blockquote>
<ul>
<li><code>负载均衡需要跟 proxy_pass 一起使用</code></li>
</ul>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">http &#123;</span><br><span class="line"><span class="meta prompt_">	#</span><span class="language-bash">httpd是服务组的名称，可随意起</span></span><br><span class="line">    upstream httpds &#123;</span><br><span class="line">        server 192.168.44.102:80;</span><br><span class="line">        server 192.168.43.103:80;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    server &#123;</span><br><span class="line">        listen       80;</span><br><span class="line"></span><br><span class="line">        location / &#123;</span><br><span class="line">        	#注意后面的httpds要跟上面的服务组的名称对应</span><br><span class="line">        	proxy_pass http://httpds;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        error_page   500 502 503 504  /50x.html;</span><br><span class="line">        location = /50x.html &#123;</span><br><span class="line">            root   html;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="5-2-负载均衡策略"><a href="#5-2-负载均衡策略" class="headerlink" title="5.2 负载均衡策略"></a>5.2 负载均衡策略</h3><h4 id="01-轮询"><a href="#01-轮询" class="headerlink" title="01 轮询"></a>01 轮询</h4><blockquote>
<p>默认情况下使用轮询方式，逐一转发，这种方式适用于无状态请求。</p>
</blockquote>
<h4 id="02-weight-权重"><a href="#02-weight-权重" class="headerlink" title="02 weight(权重)"></a>02 weight(权重)</h4><blockquote>
<p>指定轮询几率，weight和访问比率成正比，用于后端服务器性能不均的情况。</p>
<ul>
<li><p>weight    服务的权重（访问概率问题）</p>
</li>
<li><p>down    服务器下线，不可用状态</p>
</li>
<li>backup  标记为备用服务器，当前面的都挂了，再用这个（备胎）</li>
</ul>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">upstream httpd &#123;</span><br><span class="line">    server 127.0.0.1:8050 weight=10 down;</span><br><span class="line">    server 127.0.0.1:8060 weight=1;</span><br><span class="line">    server 127.0.0.1:8060 weight=1 backup;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>以下的不常用，看一看即可</p>
<p><strong>03 ip_hash</strong><br>根据客户端的ip地址转发同一台服务器，可以保持回话。</p>
<p><strong>04 least_conn</strong><br>最少连接访问</p>
<p><strong>05 url_hash</strong><br>根据用户访问的url定向转发请求</p>
<p><strong>06 fair</strong><br>根据后端服务器响应时间转发请求</p>
<h2 id="6、动静分离"><a href="#6、动静分离" class="headerlink" title="6、动静分离"></a>6、动静分离</h2><p>页面资源的链接</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line"><span class="tag">&lt;<span class="name">img</span> <span class="attr">src</span>=<span class="string">&quot;images/login.png&quot;</span> /&gt;</span></span><br><span class="line">...</span><br></pre></td></tr></table></figure>
<h3 id="01-多个location的配置方法"><a href="#01-多个location的配置方法" class="headerlink" title="01 多个location的配置方法"></a>01 多个location的配置方法</h3><blockquote>
<p>注意root 后面的是资源存放位置</p>
</blockquote>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">http &#123;</span><br><span class="line">    server &#123;</span><br><span class="line">        listen       80;</span><br><span class="line"></span><br><span class="line">        location / &#123;</span><br><span class="line">        	<span class="comment">#注意的是proxy_pass首页应该是tomcat的地址</span></span><br><span class="line">        	proxy_pass http://127.0.0.1:8080;</span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">        <span class="comment">#访问/css的路径，就在/usr/local/nginx/static里面寻找资源</span></span><br><span class="line">        <span class="comment">#现在资源不再是tomcat返回的，而是nignx返回的</span></span><br><span class="line">        location /css &#123;</span><br><span class="line">            root /usr/local/nginx/static;</span><br><span class="line">            index index.html index.htm;</span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">        location /images &#123;</span><br><span class="line">            root /usr/local/nginx/static;</span><br><span class="line">            index index.html index.htm;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        error_page   500 502 503 504  /50x.html;</span><br><span class="line">        location = /50x.html &#123;</span><br><span class="line">            root   html;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="02-单个location的配置方法"><a href="#02-单个location的配置方法" class="headerlink" title="02 单个location的配置方法"></a>02 单个location的配置方法</h3><blockquote>
<p><code>location 前缀：</code></p>
<ul>
<li>/     通用匹配，任何请求都会匹配到</li>
<li>=    精准匹配，不是以指定模式开头</li>
<li>~    正则匹配，区分大小写</li>
<li>~*   正则匹配，不区分大小写</li>
<li>^~   非正则匹配，匹配以指定模式开头的location</li>
</ul>
<p><code>location匹配顺序：</code></p>
<ul>
<li>多个正则location直接按书写顺序匹配，成功后就不会继续往后面匹配</li>
<li>普通（非正则）location会一直往下，直到找到匹配度最高的（最大前缀匹配）</li>
<li>当普通location与正则location同时存在，如果正则匹配成功,则不会再执行普通匹配</li>
<li>所有类型location存在时，“=”匹配 &gt; “^~”匹配 &gt; 正则匹配 &gt; 普通（最大前缀匹配）</li>
</ul>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">表示/css,/img,/js的请求都会匹配到</span></span><br><span class="line">location ~*/(css|img|js) &#123;</span><br><span class="line">    root /usr/local/nginx/static;</span><br><span class="line">    index index.html index.htm;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="03-alias与root"><a href="#03-alias与root" class="headerlink" title="03 alias与root"></a>03 alias与root</h3><blockquote>
<p>1）alias指定的目录是准确的，即location匹配访问的path目录下的文件直接是在alias目录下查找的；</p>
<p> 2）root指定的目录是location匹配访问的path目录的上一级目录,这个path目录一定要是真实存在root指定目录下的； </p>
<p>3）使用alias标签的目录块中不能使用rewrite的break（具体原因不明）；另外，alias指定的目录后面必须要加上”/“符号！！ </p>
<p>4）alias虚拟目录配置中，location匹配的path目录如果后面不带”/“，那么访问的url地址中这个path目录后面加不加”/“不影响访问，访问时它会自动加上”/“； 但是如果location匹配的path目录后面加上”/“，那么访问的url地址中这个path目录必须要加上”/“，访问时它不会自动加上”/“。如果不加上”/“，访问就会失败！ </p>
<p>5）root目录配置中，location匹配的path目录后面带不带”/“，都不会影响访问。</p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">root用来设置根目录，而<span class="built_in">alias</span>在接受请求的时候在路径上不会加上location</span></span><br><span class="line">location /css &#123;</span><br><span class="line">    alias /usr/local/nginx/static/css;</span><br><span class="line">    index index.html index.htm;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="04-UrlRewrite"><a href="#04-UrlRewrite" class="headerlink" title="04 UrlRewrite"></a>04 UrlRewrite</h3><p><strong>rewrite语法格式及参数语法:</strong></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">rewrite是实现URL重写的关键指令，根据regex (正则表达式)部分内容，重定向到replacement，结尾是flag标记。</span><br><span class="line"></span><br><span class="line">rewrite	  &lt;regex&gt;	&lt;replacement&gt;	[flag];</span><br><span class="line">关键字		正则  	替代内容 		 flag标记</span><br><span class="line"></span><br><span class="line">关键字：其中关键字error_log不能改变</span><br><span class="line">正则：perl兼容正则表达式语句进行规则匹配</span><br><span class="line">替代内容：将正则匹配的内容替换成replacement</span><br><span class="line">flag标记：rewrite支持的flag标记</span><br><span class="line"></span><br><span class="line">flag标记说明：</span><br><span class="line">last 		#本条规则匹配完成后，继续向下匹配新的location URI规则</span><br><span class="line">break 		#本条规则匹配完成即终止，不再匹配后面的任何规则</span><br><span class="line">redirect 	#返回302临时重定向，浏览器地址会显示跳转后的URL地址</span><br><span class="line">permanent 	#返回301永久重定向，浏览器地址栏会显示跳转后的URL地址</span><br></pre></td></tr></table></figure>
<blockquote>
<p>rewrite参数的标签段位置：<br>server,location,if</p>
</blockquote>
<p><strong>实例</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">http &#123;</span><br><span class="line">    server &#123;</span><br><span class="line">        listen       80;</span><br><span class="line">        location / &#123;</span><br><span class="line">        	#表示匹配 /xxx.html， 真实地址是/index.jsp?pageNum=xxx</span><br><span class="line">        	#如果后面是 break， 则浏览器地址栏不会变化</span><br><span class="line">        	#如果是redirect，则浏览器地址栏会变成重定向的地址</span><br><span class="line">        	rewrite ^/([0-9]+).html$ /index.jsp?pageNum=$1 break;</span><br><span class="line">        	proxy_pass http://127.0.0.1:8080;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="7、网关服务器"><a href="#7、网关服务器" class="headerlink" title="7、网关服务器"></a>7、网关服务器</h2><p>配置统一的入口，后面的tomcat服务器只能通过网关服务器来访问，不对外开放</p>
<h3 id="7-1-配置tomcat的防火墙"><a href="#7-1-配置tomcat的防火墙" class="headerlink" title="7.1 配置tomcat的防火墙"></a>7.1 配置tomcat的防火墙</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">开启防火墙</span></span><br><span class="line">systemctl start firewalld</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">重启防火墙</span></span><br><span class="line">systemctl restart firewalld</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">重载规则</span></span><br><span class="line">firewall-cmd --reload</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">查看已配置规则</span></span><br><span class="line">firewall-cmd --list-all</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">指定端口和ip访问，192.168.44.101是网关服务器的地址，8080是当前服务器开放的端口</span></span><br><span class="line">firewall-cmd --permanent --add-rich-rule=&quot;rule family=&quot;ipv4&quot; source address=&quot;192.168.44.101&quot;</span><br><span class="line">port protocol=&quot;tcp&quot; port=&quot;8080&quot; accept&quot;</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">移除规则</span></span><br><span class="line">firewall-cmd --permanent --remove-rich-rule=&quot;rule family=&quot;ipv4&quot; source</span><br><span class="line">address=&quot;192.168.44.101&quot; port port=&quot;8080&quot; protocol=&quot;tcp&quot; accept&quot;</span><br></pre></td></tr></table></figure>
<h3 id="7-2-配置nginx"><a href="#7-2-配置nginx" class="headerlink" title="7.2 配置nginx"></a>7.2 配置nginx</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">upstream httpds &#123;</span><br><span class="line">    server 192.168.44.102 weight=8 down;</span><br><span class="line">    server 192.168.44.103:8080 weight=2;</span><br><span class="line">    server 192.168.44.104:8080 weight=1 backup;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">http &#123;</span><br><span class="line">    server &#123;</span><br><span class="line">        listen       80;</span><br><span class="line">        location / &#123;</span><br><span class="line">        	rewrite ^/([0-9]+).html$ /index.jsp?pageNum=$1 break;</span><br><span class="line">        	proxy_pass http://httpds;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="8、防盗链配置"><a href="#8、防盗链配置" class="headerlink" title="8、防盗链配置"></a>8、防盗链配置</h2><blockquote>
<p>原理是检测请求头里面的Referer是否允许访问，注意第一次是不带Referer</p>
</blockquote>
<h3 id="8-1-语法"><a href="#8-1-语法" class="headerlink" title="8.1 语法"></a>8.1 语法</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">valid_referers none | blocked | server_names | strings ....;</span><br><span class="line"></span><br><span class="line">none 			检测 Referer 头域不存在的情况。</span><br><span class="line">blocked			检测 Referer 头域的值被防火墙或者代理服务器删除或伪装的情况。这种情况该头域的值不以“http://” 或 “https://” 开头。</span><br><span class="line">server_names 	设置一个或多个 URL ，检测 Referer 头域的值是否是这些 URL 中的某一个。</span><br></pre></td></tr></table></figure>
<h3 id="8-2-location中配置"><a href="#8-2-location中配置" class="headerlink" title="8.2 location中配置"></a>8.2 location中配置</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">http &#123;</span><br><span class="line">    server &#123;</span><br><span class="line">        listen       80;</span><br><span class="line">        location / &#123;</span><br><span class="line">        	#防盗链配置，192.168.44.101是允许的主机，可以写多台</span><br><span class="line">        	valid_referers 192.168.44.101;</span><br><span class="line">            if ($invalid_referer) &#123;</span><br><span class="line">            	#直接返回状态码</span><br><span class="line">                return 403;</span><br><span class="line">                </span><br><span class="line">                #可以直接返回配置好的错误页面</span><br><span class="line">                #return /403.html;</span><br><span class="line">                </span><br><span class="line">                #可以配置urlRewrite，直接返回一张图片</span><br><span class="line">                #rewrite ^/ /img/error.png break;</span><br><span class="line">            &#125;</span><br><span class="line">            </span><br><span class="line">        	root   html;</span><br><span class="line">            index  index.html index.htm;</span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">        #配置防盗链返回的错误页面</span><br><span class="line">        error_page 403  /403.html;</span><br><span class="line">        location = /403.html &#123;</span><br><span class="line">            root   html;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="9、高可用配置"><a href="#9、高可用配置" class="headerlink" title="9、高可用配置"></a>9、高可用配置</h2><h3 id="9-1-Keepalived"><a href="#9-1-Keepalived" class="headerlink" title="9.1 Keepalived"></a>9.1 Keepalived</h3><p>yum安装</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install -y keepalived</span><br></pre></td></tr></table></figure>
<h3 id="9-2-最小配置"><a href="#9-2-最小配置" class="headerlink" title="9.2 最小配置"></a>9.2 最小配置</h3><blockquote>
<p>使用yum安装后配置文件在    /etc/keepalived/keepalived.conf</p>
</blockquote>
<p>01 第一台机器配置</p>
<blockquote>
<p>想要机器在同一个组，必须保证  实例id，virtual_router_id，authentication相同！！</p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">! Configuration File for keepalived</span><br><span class="line">global_defs &#123;</span><br><span class="line"><span class="meta prompt_">	#</span><span class="language-bash">router_id必须是唯一的</span></span><br><span class="line">	router_id lb111</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">实例<span class="built_in">id</span>，想要两台机器在同一个组，必须要相同</span></span><br><span class="line">vrrp_instance 实例id &#123;</span><br><span class="line"><span class="meta prompt_">	#</span><span class="language-bash">标记当前的机器是mater</span></span><br><span class="line">    state MASTER</span><br><span class="line">    #使用的网卡</span><br><span class="line">    interface ens33</span><br><span class="line">    #想要两台机器在同一个组，必须要相同</span><br><span class="line">    virtual_router_id 51</span><br><span class="line">    #权重，越高越容易拿到虚拟ip地址</span><br><span class="line">    priority 100</span><br><span class="line">    advert_int 1</span><br><span class="line">    #想要两台机器在同一个组，必须要相同</span><br><span class="line">    authentication &#123;</span><br><span class="line">        auth_type PASS</span><br><span class="line">        auth_pass 1111</span><br><span class="line">    &#125;</span><br><span class="line">    #对面访问的虚拟ip地址</span><br><span class="line">    virtual_ipaddress &#123;</span><br><span class="line">        192.168.44.200</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>02 第二台机器配置</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">! Configuration File for keepalived</span><br><span class="line">global_defs &#123;</span><br><span class="line">	router_id lb110</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">vrrp_instance 实例id &#123;</span><br><span class="line"><span class="meta prompt_">	#</span><span class="language-bash">标记当前的机器是备用机器</span></span><br><span class="line">    state BACKUP</span><br><span class="line">    interface ens33</span><br><span class="line">    virtual_router_id 51</span><br><span class="line">    priority 50</span><br><span class="line">    advert_int 1</span><br><span class="line">    authentication &#123;</span><br><span class="line">        auth_type PASS</span><br><span class="line">        auth_pass 1111</span><br><span class="line">    &#125;</span><br><span class="line">    virtual_ipaddress &#123;</span><br><span class="line">    	192.168.44.200</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>03 配置完成需要启动</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">systemctl start keepalived</span><br><span class="line">systemctl status keepalived</span><br></pre></td></tr></table></figure>
</article><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/nginx/">nginx</a></div><div class="post_share"></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/blog/nginx/Nginx%20%E9%85%8D%E7%BD%AE%E8%AF%A6%E8%A7%A3%20/"><img class="prev-cover" src= "" data-lazy-src="/images/nginx.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Nginx 配置详解</div></div></a></div><div class="next-post pull-right"><a href="/blog/jenkins/Jenkins/"><img class="next-cover" src= "" data-lazy-src="/images/jenkins_cover.jpeg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Jenkins 简单使用</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/blog/nginx/Nginx 配置详解 /" title="Nginx 配置详解"><img class="cover" src= "" data-lazy-src="/images/nginx.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-18</div><div class="title">Nginx 配置详解</div></div></a></div><div><a href="/blog/linux/Linux常用软件安装/" title="Linux常用软件安装"><img class="cover" src= "" data-lazy-src="/images/linux.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-09-16</div><div class="title">Linux常用软件安装</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">一切解释权归本咸鱼所有</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#0%E3%80%81Nginx-%E5%AE%89%E8%A3%85"><span class="toc-number">1.</span> <span class="toc-text">0、Nginx 安装</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%85%B3%E9%97%AD%E9%98%B2%E7%81%AB%E5%A2%99"><span class="toc-number"></span> <span class="toc-text">关闭防火墙</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E7%A6%81%E6%AD%A2%E9%98%B2%E7%81%AB%E5%A2%99%E5%BC%80%E6%9C%BA%E5%90%AF%E5%8A%A8"><span class="toc-number"></span> <span class="toc-text">禁止防火墙开机启动</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%94%BE%E8%A1%8C%E7%AB%AF%E5%8F%A3"><span class="toc-number"></span> <span class="toc-text">放行端口</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E9%87%8D%E5%90%AF%E9%98%B2%E7%81%AB%E5%A2%99"><span class="toc-number"></span> <span class="toc-text">重启防火墙</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1%E3%80%81%E7%9B%AE%E5%BD%95%E7%BB%93%E6%9E%84"><span class="toc-number">1.</span> <span class="toc-text">1、目录结构</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2%E3%80%81%E6%9C%80%E5%B0%8F%E5%8C%96%E9%85%8D%E7%BD%AE"><span class="toc-number">2.</span> <span class="toc-text">2、最小化配置</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3%E3%80%81%E8%99%9A%E6%8B%9F%E4%B8%BB%E6%9C%BA"><span class="toc-number">3.</span> <span class="toc-text">3、虚拟主机</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4%E3%80%81%E5%8F%8D%E5%90%91%E4%BB%A3%E7%90%86"><span class="toc-number">4.</span> <span class="toc-text">4、反向代理</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5%E3%80%81%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1"><span class="toc-number">5.</span> <span class="toc-text">5、负载均衡</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#5-1-%E9%85%8D%E7%BD%AE%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1"><span class="toc-number">5.1.</span> <span class="toc-text">5.1 配置负载均衡</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-2-%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E7%AD%96%E7%95%A5"><span class="toc-number">5.2.</span> <span class="toc-text">5.2 负载均衡策略</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#01-%E8%BD%AE%E8%AF%A2"><span class="toc-number">5.2.1.</span> <span class="toc-text">01 轮询</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#02-weight-%E6%9D%83%E9%87%8D"><span class="toc-number">5.2.2.</span> <span class="toc-text">02 weight(权重)</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#6%E3%80%81%E5%8A%A8%E9%9D%99%E5%88%86%E7%A6%BB"><span class="toc-number">6.</span> <span class="toc-text">6、动静分离</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#01-%E5%A4%9A%E4%B8%AAlocation%E7%9A%84%E9%85%8D%E7%BD%AE%E6%96%B9%E6%B3%95"><span class="toc-number">6.1.</span> <span class="toc-text">01 多个location的配置方法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#02-%E5%8D%95%E4%B8%AAlocation%E7%9A%84%E9%85%8D%E7%BD%AE%E6%96%B9%E6%B3%95"><span class="toc-number">6.2.</span> <span class="toc-text">02 单个location的配置方法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#03-alias%E4%B8%8Eroot"><span class="toc-number">6.3.</span> <span class="toc-text">03 alias与root</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#04-UrlRewrite"><span class="toc-number">6.4.</span> <span class="toc-text">04 UrlRewrite</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#7%E3%80%81%E7%BD%91%E5%85%B3%E6%9C%8D%E5%8A%A1%E5%99%A8"><span class="toc-number">7.</span> <span class="toc-text">7、网关服务器</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#7-1-%E9%85%8D%E7%BD%AEtomcat%E7%9A%84%E9%98%B2%E7%81%AB%E5%A2%99"><span class="toc-number">7.1.</span> <span class="toc-text">7.1 配置tomcat的防火墙</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#7-2-%E9%85%8D%E7%BD%AEnginx"><span class="toc-number">7.2.</span> <span class="toc-text">7.2 配置nginx</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#8%E3%80%81%E9%98%B2%E7%9B%97%E9%93%BE%E9%85%8D%E7%BD%AE"><span class="toc-number">8.</span> <span class="toc-text">8、防盗链配置</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#8-1-%E8%AF%AD%E6%B3%95"><span class="toc-number">8.1.</span> <span class="toc-text">8.1 语法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#8-2-location%E4%B8%AD%E9%85%8D%E7%BD%AE"><span class="toc-number">8.2.</span> <span class="toc-text">8.2 location中配置</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#9%E3%80%81%E9%AB%98%E5%8F%AF%E7%94%A8%E9%85%8D%E7%BD%AE"><span class="toc-number">9.</span> <span class="toc-text">9、高可用配置</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#9-1-Keepalived"><span class="toc-number">9.1.</span> <span class="toc-text">9.1 Keepalived</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#9-2-%E6%9C%80%E5%B0%8F%E9%85%8D%E7%BD%AE"><span class="toc-number">9.2.</span> <span class="toc-text">9.2 最小配置</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/blog/java/01%20Spring%20Security%20&amp;%20oauth2/" title="Spring Security &amp; Oauth2"><img src= "" data-lazy-src="/images/spring-security.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Spring Security &amp; Oauth2"/></a><div class="content"><a class="title" href="/blog/java/01%20Spring%20Security%20&amp;%20oauth2/" title="Spring Security &amp; Oauth2">Spring Security &amp; Oauth2</a><time datetime="2024-04-25T07:24:45.000Z" title="发表于 2024-04-25 15:24:45">2024-04-25</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/java/02%20JWT%E5%B7%A5%E5%85%B7%E7%B1%BB/" title="JWT工具类"><img src= "" data-lazy-src="/images/jwt.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="JWT工具类"/></a><div class="content"><a class="title" href="/blog/java/02%20JWT%E5%B7%A5%E5%85%B7%E7%B1%BB/" title="JWT工具类">JWT工具类</a><time datetime="2024-04-25T07:24:45.000Z" title="发表于 2024-04-25 15:24:45">2024-04-25</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/java/00%20Security%20%E9%9B%86%E6%88%90%E7%A4%BA%E4%BE%8B/" title="SpringSecurity 集成示例"><img src= "" data-lazy-src="/images/spring-security.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="SpringSecurity 集成示例"/></a><div class="content"><a class="title" href="/blog/java/00%20Security%20%E9%9B%86%E6%88%90%E7%A4%BA%E4%BE%8B/" title="SpringSecurity 集成示例">SpringSecurity 集成示例</a><time datetime="2024-04-25T07:24:43.000Z" title="发表于 2024-04-25 15:24:43">2024-04-25</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/java/101%20Mybatis-plus%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90/" title="MybatisPlus 快速集成"><img src= "" data-lazy-src="/images/mybatis-plus.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="MybatisPlus 快速集成"/></a><div class="content"><a class="title" href="/blog/java/101%20Mybatis-plus%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90/" title="MybatisPlus 快速集成">MybatisPlus 快速集成</a><time datetime="2024-04-21T07:39:43.000Z" title="发表于 2024-04-21 15:39:43">2024-04-21</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/java/10%20Mybatis%20%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90/" title="Mybatis 快速集成"><img src= "" data-lazy-src="/images/mybaits.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Mybatis 快速集成"/></a><div class="content"><a class="title" href="/blog/java/10%20Mybatis%20%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90/" title="Mybatis 快速集成">Mybatis 快速集成</a><time datetime="2024-04-21T07:24:43.000Z" title="发表于 2024-04-21 15:24:43">2024-04-21</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2024 By mowei</div><div class="footer_custom_text">海内存知已，天涯若比邻</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="font-plus" type="button" title="放大字体"><i class="fas fa-plus"></i></button><button id="font-minus" type="button" title="缩小字体"><i class="fas fa-minus"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="/js/search/local-search.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"><script>if (document.getElementsByClassName('mermaid').length) {
  if (window.mermaidJsLoad) mermaid.init()
  else {
    getScript('https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js').then(() => {
      window.mermaidJsLoad = true
      mermaid.initialize({
        theme: 'default',
      })
      true && mermaid.init()
    })
  }
}</script></div><div class="aplayer no-destroy" data-id="9385310356" data-server="netease" data-type="playlist" data-fixed="true" data-mini="true" data-listFolded="false" data-order="random" data-preload="none" data-autoplay="true" muted></div><canvas class="fireworks" mobile="false"></canvas><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/fireworks.min.js"></script><script defer="defer" id="fluttering_ribbon" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js"></script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/gh/metowolf/MetingJS@1.2/dist/Meting.min.js"></script><script src="https://cdn.jsdelivr.net/npm/pjax/pjax.min.js"></script><script>let pjaxSelectors = [
  'title',
  '#config-diff',
  '#body-wrap',
  '#rightside-config-hide',
  '#rightside-config-show',
  '.js-pjax'
]

if (false) {
  pjaxSelectors.unshift('meta[property="og:image"]', 'meta[property="og:title"]', 'meta[property="og:url"]')
}

var pjax = new Pjax({
  elements: 'a:not([target="_blank"])',
  selectors: pjaxSelectors,
  cacheBust: false,
  analytics: false,
  scrollRestoration: false
})

document.addEventListener('pjax:send', function () {

  // removeEventListener scroll 
  window.removeEventListener('scroll', window.tocScrollFn)
  window.removeEventListener('scroll', scrollCollect)

  typeof preloader === 'object' && preloader.initLoading()
  
  if (window.aplayers) {
    for (let i = 0; i < window.aplayers.length; i++) {
      if (!window.aplayers[i].options.fixed) {
        window.aplayers[i].destroy()
      }
    }
  }

  typeof typed === 'object' && typed.destroy()

  //reset readmode
  const $bodyClassList = document.body.classList
  $bodyClassList.contains('read-mode') && $bodyClassList.remove('read-mode')

})

document.addEventListener('pjax:complete', function () {
  window.refreshFn()

  document.querySelectorAll('script[data-pjax]').forEach(item => {
    const newScript = document.createElement('script')
    const content = item.text || item.textContent || item.innerHTML || ""
    Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
    newScript.appendChild(document.createTextNode(content))
    item.parentNode.replaceChild(newScript, item)
  })

  GLOBAL_CONFIG.islazyload && window.lazyLoadInstance.update()

  typeof chatBtnFn === 'function' && chatBtnFn()
  typeof panguInit === 'function' && panguInit()

  // google analytics
  typeof gtag === 'function' && gtag('config', '', {'page_path': window.location.pathname});

  // baidu analytics
  typeof _hmt === 'object' && _hmt.push(['_trackPageview',window.location.pathname]);

  typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting()

  // Analytics
  if (false) {
    MtaH5.pgv()
  }

  // prismjs
  typeof Prism === 'object' && Prism.highlightAll()

  typeof preloader === 'object' && preloader.endLoading()
})

document.addEventListener('pjax:error', (e) => {
  if (e.request.status === 404) {
    pjax.loadUrl('/404.html')
  }
})</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><script src="/live2d_models/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2d_models/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2d_models/assets/wanko.model.json"},"display":{"position":"left","width":100,"height":150,"hOffset":-10,"vOffset":40},"mobile":{"show":true},"react":{"opacity":0.7},"log":false});</script></body></html>